package com.leetCode.problem;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-11-04 17:47:34
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-11-04     张李鑫                     1.0         1.0 Version
 */
public class Problem26 {

    public static int removeDuplicates(int[] arr) {
        int index=0;
        int r=1;
        int length=arr.length;
        while (index<length&&r<length){
            if (arr[index]==arr[r]){
                r++;
            }else {
                swap(arr,r++,++index);
            }
        }
        return ++index;
    }

    public static void  swap(int []arr,int l,int r){
        int temp=arr[l];
        arr[l]=arr[r];
        arr[r]=temp;
    }

    public static void main(String[] args) {
        int []arr={1,1,1,1,1,2,2,2,2,3};
        System.out.println(removeDuplicates(arr));
    }

}
